﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WOS.Logging
{
    public sealed class LogSource
    {
        #region Constants
        public static readonly LogSource Default = new LogSource(String.Empty, "Default");
        #endregion
        #region Private Fields
        private readonly string code;
        private readonly string name;
        private readonly List<LogTag> tags;
        #endregion
        #region Constructors
        public LogSource(string code, string name)
        {
            this.code = code;
            this.name = name;
            this.tags = new List<LogTag>();
        }

        private LogSource(LogSource source, LogTag[] tags)
        {
            this.code = source.Code;
            this.name = source.Name;

            this.tags = new List<LogTag>(source.Tags);
            this.tags.AddRange(tags);
        }
        #endregion

        #region Public Members
        public string Code
        {
            get { return this.code; }
        }

        public string Name
        {
            get { return this.name; }
        }

        public LogTag[] Tags
        {
            get { return this.tags.ToArray(); }
        }

        public LogSource Tag(params LogTag[] tags)
        {
            return new LogSource(this, tags);
        }

        public bool IsChildOf(LogSource parent)
        {
            if (this.Code != parent.Code)
                return false;

            return true;
        }
        #endregion
        #region Overridden Members
        public override int GetHashCode()
        {
            return this.code.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            var second = obj as LogSource;

            if (second == null || second.Code != this.Code)
                return false;

            return true;
        }
        #endregion
    }
}
